/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * XinxetoTextView.java
 *
 * Created on 29/05/2011, 20:03:57
 */

package presentation;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
/**
 *
 * @author Andreu Marimon
 */


public class XinxetoTextView extends JPanel {
    private static final int START = 1;
    private static final int NOMIN = 2;
    private static final int ADDVERB = 3;
    private static final int PRIORITY = 4;
    private static final int NEXT = 5;
    boolean _enabled = false;
    PresentationController _pCntrl;


    public void quitText () {
	_enabled = false;
	jScrollPane2.setVisible(false);
	_xinxetoText.setVisible(false);
	_xinxetoText.repaint();
	validate();
	repaint();
    }

    public void setXinxetoText (int text){
	if (_pCntrl.getAssistant() == 1) {
	    _enabled = true;
	    jScrollPane2.setVisible(true);
	    _xinxetoText.setVisible(true);
	    if (text == START) _xinxetoText.setText("Hi! I'm Xinxeto and I'll be your guide here in Nominalitzador 2011. Click me if you need help");
	    if (text == NOMIN) _xinxetoText.setText("I noticed you started a nominalization process. The program will select all verbs in text and show the first one");
	    if (text == ADDVERB) _xinxetoText.setText("If you add a verb (infinitive), the program will select and nominalize it the next time you enter the program");
	    if (text == PRIORITY) _xinxetoText.setText("Increasing priority of a correct nominalization helps the program to find better solutions on new verbs!");
	    if (text == NEXT) _xinxetoText.setText("You can also move between the verbs by clicking on the text area");
	    validate();
	    repaint();
	}
    }
    
    /** Creates new form XinxetoTextView */

    public XinxetoTextView(PresentationController pCntrl) {
        _pCntrl = pCntrl;
	initComponents();
	_xinxetoText.setVisible(false);
	jScrollPane2.setVisible(false);
	jScrollPane2.setOpaque(false);
	//jScrollPane2.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        _xinxetoText = new javax.swing.JTextPane();

        setBackground(new java.awt.Color(255, 255, 255));
        setMaximumSize(new java.awt.Dimension(222, 74));
        setMinimumSize(new java.awt.Dimension(222, 74));
        setPreferredSize(new java.awt.Dimension(222, 74));
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                click(evt);
            }
        });

        jScrollPane2.setBackground(new java.awt.Color(255, 153, 0));
        jScrollPane2.setBorder(null);

        _xinxetoText.setBackground(new java.awt.Color(255, 178, 34));
        _xinxetoText.setBorder(null);
        _xinxetoText.setEditable(false);
        _xinxetoText.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        _xinxetoText.setAutoscrolls(false);
        _xinxetoText.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                click(evt);
            }
        });
        jScrollPane2.setViewportView(_xinxetoText);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void click(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_click
	quitText();
    }//GEN-LAST:event_click


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextPane _xinxetoText;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (_pCntrl.getAssistant() != 0) {
	    ImageIcon background;
	    String slash = System.getProperty("file.separator");
	    String path;
	    String jarPath = System.getProperty("java.class.path");
	    int _lastSlash = jarPath.lastIndexOf(slash);
	    path = jarPath.substring(0,_lastSlash + 1);
	    if (_enabled) {
		background = new ImageIcon(path+"imatges"+slash+"xinxetoText.png");
	    }
	    else {
		background = new ImageIcon(path+"imatges"+slash+"empty.png");
	    }
	    g.clearRect(0, 0, 222, 74);
	    g.drawImage(background.getImage(), 0, 0, 222, 74, null );
	}
    }
}
